<script setup lang="ts">
import { ref, watch } from 'vue';

// 1. 使用 watch 监听一个响应式数据
const money = ref(100)
const car = ref('共享单车')
watch(money, (newValue, oldValue) => {
  if (newValue > 25000 &&newValue<100000) {
    car.value = '电动车'
  } else if (newValue > 100000) {car.value='比亚迪*秦' }
 })
//2.监听多个响应式数据
watch([car, money], (newValue, oldValue) => {
  console.log(`旧值:${oldValue}`, `新值: ${newValue}`);
  
 })
</script>

<template>
  <div id="app">
    <div> 钱包：{{ money }}</div>
    <button @click="money+=15000 ">搬砖一个月</button>
    <div>座驾：{{ car }}</div>
    <button @click="car='电动车' "></button>
  </div>
</template>

<style></style>